using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShellAnywhere.Model
{
	public abstract class StreamProcessor<Input, Output>
	{
		#region ctors
		public StreamProcessor(Stream<Input> inputStream, Stream<Output> outputStream)
		{
			InputStream = inputStream;
			OutputStream = outputStream;
		}
		#endregion ctors

		#region properties
		public abstract Stream<Input> InputStream { get; set; }
		public abstract Stream<Output> OutputStream { get; set; }

		public virtual bool IsEmpty { get { return InputStream.Count == 0; } }
		public virtual bool IsComplete { get { return InputStream.IsEndOfStream; } }
		#endregion properties

		#region methods
		public virtual void Evaluate()
		{
			Output item = default(Output);
			OutputStream.ClearItems();

			while ((item = NextOutputItem()) != null)
			{
				OutputStream.AddItems(item);
			}
		}
		public virtual void Reset()
		{
			InputStream.Position = 0;
			OutputStream.ClearItems();
		}
		public virtual void Clear()
		{
			InputStream.ClearItems();
			OutputStream.ClearItems();
		}
		public abstract Output NextOutputItem();
		#endregion methods

		#region fields
		#endregion fields
	}
}
